package logger

import (
	"encoding/json"
	"kubeInstall/conf"
	"kubeInstall/utils/file"
	"runtime"
)

func SetLoggerInit() {
	config := new(LogConfig)

	if conf.LogSetting.LogType == AdapterConsole || conf.LogSetting.LogType == "" {
		config = &LogConfig{
			TimeFormat: logTimeDefaultFormat,
			Console: &ConsoleLogger{
				Colorful: runtime.GOOS != "windows",
				LogLevel: conf.LogSetting.LogLevel,
			},
		}
	}

	if conf.LogSetting.LogType == AdapterFile {
		config = &LogConfig{
			TimeFormat: logTimeDefaultFormat,
			File: &FileLogger{
				Filename: file.CombineFile(conf.LogSetting.LogSavePath, conf.LogSetting.LogFileName),
				Append:   true,
				Daily:    true,
				LogLevel: conf.LogSetting.LogLevel,
			},
		}
	}
	if conf.LogSetting.LogType == AdapterConn {
		config = &LogConfig{
			TimeFormat: logTimeDefaultFormat,
			Conn: &ConnLogger{
				LogLevel: conf.LogSetting.LogLevel,
			},
		}

	}

	cfg, _ := json.Marshal(config)
	SetLogger(string(cfg))
	SetLogPath(true)
}
